<template>
  <div class="edit-enterprise-detail" v-if="props.showDialog">
    <Dialog
      diaTop="5"
      headerName="编辑"
      :showDialog="true"
      @close="close"
      @save="save"
      saveLetter="保存"
      diaWidth="55"
      footerTop="10"
    >
      <template #content>
        <div class="content-wrap">
          <el-form
            ref="formRef"
            :model="formData"
            :rules="rules"
            label-width="168px"
          >
            <el-row :gutter="60">
              <el-col :span="12">
                <el-form-item label="企业名称：" prop="customername">
                  <el-input v-model="formData.customername" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="排污许可证号：" prop="dischargelicense">
                  <el-input clearable v-model="formData.dischargelicense" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="60">
              <el-col :span="12">
                <el-form-item label="区域：" prop="district">
                  <el-tree-select
                    v-model="formData.district"
                    :data="adminAreaList"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="年产废规模：" prop="wastescale">
                  <el-input clearable v-model="formData.wastescale" />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item label="管辖地：" prop="district">
                  <el-select v-model="formData.district" placeholder="请选择">
                    <el-option
                      v-for="item in adminManageList"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col> -->
            </el-row>
            <el-row :gutter="60">
              <el-col :span="12">
                <el-form-item label="详细地址：" prop="customeraddress">
                  <el-input clearable v-model="formData.customeraddress" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="环保管理员1：" prop="hbperson">
                  <el-input clearable v-model="formData.hbperson" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="60">
              <el-col :span="12">
                <el-form-item label="手机号1：" prop="hbmobile">
                  <el-input clearable v-model="formData.hbmobile" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="环保管理员2：" prop="hbpersonsecond">
                  <el-input clearable v-model="formData.hbpersonsecond" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="60">
              <el-col :span="12">
                <el-form-item label="手机号2：" prop="hbmobilesecond">
                  <el-input clearable v-model="formData.hbmobilesecond" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="企业类型：" prop="managementtype">
                  <el-input clearable v-model="formData.managementtype" />
                </el-form-item>
              </el-col>
            </el-row>
            <!-- <el-row :gutter="60">
              <el-col :span="12">
                <el-form-item label="企业状态：" prop="status">
                  <el-input clearable v-model="formData.status" />
                </el-form-item>
              </el-col>
            </el-row> -->
            <el-row :gutter="60">
              <el-col :span="24">
                <el-form-item
                  label="排污许可证二维码："
                  label-width="210"
                  prop="dischargelicenseurl"
                >
                  <div class="qr-code">
                    <Upload
                      :ref="
                        (res) => {
                          if (res.imgUrl) {
                            formData.dischargelicenseurl = res.imgUrl;
                          }
                        }
                      "
                    >
                      <template #content>
                        <div class="content">
                          <img :src="formData.dischargelicenseurl" alt="" />
                          <button>点击上传</button>
                        </div>
                      </template>
                    </Upload>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </template>
    </Dialog>
  </div>
</template>
<script setup>
import Dialog from "@/components/DialogCross";
import Upload from "@/components/Upload";
import http from "@http";
import changeArea from "@/utils/changeArea.js";
import ElMessage from "@/components/ElMessage.js";
let props = defineProps(["showDialog", "enterpriseDetail"]);

let emit = defineEmits(["update:showDialog", "save"]);
let formData = reactive({});
let adminManageList = ref([]);
let formRef = ref(null);
let adminAreaList = ref([]);
watch(
  () => props.enterpriseDetail,
  (data) => {
    for (let key in data) {
      formData[key] = data[key];
    }
    formData.district = Number(formData.district);
  },
  { deep: true }
);
let close = () => {
  emit("update:showDialog", false);
};
let save = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      http({ url: "/admPCEnterprise/update", data: formData }).then(
        (res) => {
          // if (res.code == 0) {
          //   ElMessage({
          //     msg: "编辑成功",
          //   });
          // }
          emit("update:showDialog", false);
          emit("save");
         
        }
      );
    }
  });

  // emit("save");
};
http({ url: "/region/datalisttree" }).then((res) => {
  console.log(res, "res");
  if (res.code == 0) {
    adminAreaList.value = changeArea(res.data);
  }
});
let validateNum = (rule, value, callback) => {
  let reg = /^1\d{10}$/;
  if (!reg.test(value)) {
    callback(new Error(rule.message));
    return;
  }
  callback();
};
let rules = {
  customername: [
    {
      required: true,
      message: "企业名称不能为空",
      trigger: "blur",
    },
  ],
  dischargelicense: [
    {
      required: true,
      message: "排污许可证号不能为空",
      trigger: "blur",
    },
  ],
  district: [
    {
      required: true,
      message: "区域不能为空",
      trigger: "blur",
    },
  ],
  enterpriseName: [
    {
      required: true,
      message: "年产废规模不能为空",
      trigger: "blur",
    },
  ],
  customeraddress: [
    {
      required: true,
      message: "详细地址不能为空",
      trigger: "blur",
    },
  ],
  hbperson: [
    {
      required: true,
      message: "环保管理员1不能为空",
      trigger: "blur",
    },
  ],
  wastescale: [
    {
      required: true,
      message: "年产废规模不能为空",
      trigger: "blur",
    },
  ],
  hbmobile: [
    {
      required: true,
      message: "手机号1不能为空",
      trigger: "blur",
    },

    {
      validator: validateNum,
      trigger: "blur",
      message: "请输入正确的手机号码",
    },
  ],
  hbpersonsecond: [
    {
      required: true,
      message: "环保管理员2不能为空",
      trigger: "blur",
    },
  ],
  hbmobilesecond: [
    {
      required: true,
      message: "手机号2不能为空",
      trigger: "blur",
    },
    {
      validator: validateNum,
      trigger: "blur",
      message: "请输入正确的手机号码",
    },
  ],
  dischargelicenseurl: [
    {
      required: true,
      message: "排污许可证二维码不能为空",
      trigger: "blur",
    },
  ],
};
</script>
<style lang="scss" scoped>
/* 编辑企业详情页面 */
.edit-enterprise-detail {
  .content-wrap {
    padding-right: 10px;
     :deep(.el-input){
      width: 100%;
     }
    .qr-code {
      width: 826px;
      height: 263px;
      background: #ffffff;
      border-radius: 5px;
      border: 1px solid #bfbfbf;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      .content {
        display: flex;
        flex-direction: column;
        img {
          width: 190px;
          height: 182px;
        }
        button {
          margin-top: 5px;

          font-family: Source Han Sans CN;
          font-weight: 500;
          font-size: 20px;
          color: #0874fa;
        }
      }
    }
  }

  :deep(.el-form-item__label) {
    font-family: Source Han Sans CN;
    font-weight: 500 !important;
    font-size: 20px !important;
    color: #000 !important;
  }
  :deep(.el-input) {
    width: 344px;

    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 18px;
    color: #666666 !important;
  }
  :deep(.el-input__inner) {
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 18px;
    color: #666666;
  }
  :deep(.el-input__wrapper, .el-textarea__inner) {
    box-shadow: none;
    font-family: Source Han Sans CN;
    font-weight: 400 !important;
    font-size: 18px !important;
    color: #666666 !important;
    background: #fff !important;
    border-radius: 5px !important;
    border: 1px solid #bfbfbf !important;

    height: 37px !important;
  }
 
 
}
</style>
